"use strict"  // Use strict JavaScript mode
    
// Pull in the modules we're going to use
var cocos  = require('cocos2d')   // Import the cocos2d module
  , nodes  = cocos.nodes          // Convenient access to 'nodes'
  , events = require('events')    // Import the events module
  , geom    = require('geometry')  // Import the geometry module
  , ccp    = geom.ccp             // Short hand to create points
  ,Texture2D = require('cocos2d/Texture2D').Texture2D
  , about_scene = require('/about_scene')
  , difficulty_scene = require('/difficulty_scene')
  
// Convenient access to some constructors
var Layer    = nodes.Layer
  , Scene    = nodes.Scene
  , Label    = nodes.Label
  , Director = cocos.Director

function title_scene(){
	        title_scene.superclass.constructor.call(this)
	
	
		// Add a background sprite.
		var sprite_bg = new cocos.nodes.Sprite({
		    file: '/resources/title.png',
		    rect: new geom.Rect(0,0, 600,600)
		});
		 
		sprite_bg.anchorPoint = new geom.Point(0, 0);
		sprite_bg.position = new geom.Point(0,-100);
		this.addChild({child: sprite_bg});
		this.contentSize = sprite_bg.contentSize;

		
		// Fullscreen button....................................................................................................................................
		var item1 = new cocos.nodes.MenuItemImage({ 
					normalImage: "/resources/start.png",
                                        selectedImage: "/resources/start.png",
					callback: this.toDifficultyCallback.bind(this) })
			
		this.contentSize = item1.contentSize
		item1.anchorPoint = new geom.Point(0,0)
		item1.position = new geom.Point(130,160)	
					
		var item2 = new cocos.nodes.MenuItemImage({ 
					normalImage: "/resources/about.png",
                                        selectedImage: "/resources/about.png",
					callback: this.toAboutCallback.bind(this) })
			
		this.contentSize = item2.contentSize
		item2.anchorPoint = new geom.Point(0,0)
		item2.position = new geom.Point(130,100)	
		
					
		var item3 = new cocos.nodes.MenuItemImage({ 
					normalImage: "/resources/exit.png",
                                        selectedImage: "/resources/exit.png",
					callback: this.toTitleCallback.bind(this) })
			
		this.contentSize = item3.contentSize
		item3.anchorPoint = new geom.Point(0,0)
		item3.position = new geom.Point(130,40)	
		
		
					
					
		var menu = new cocos.nodes.Menu({ items: [item1,item2,item3] })
		menu.position = geom.ccp(0, 0)
		this.addChild({child: menu})
		//*******************************************************************************************
}


title_scene.inherit(cocos.nodes.Layer, {
    _title: 'No title',
    subtitle: null,

    get title () {
        return this._title
    },

    set title (newTitle) {
        this._title = newTitle
    },

    restartCallback: function () {
        var director = cocos.Director.sharedDirector

        var scene = new nodes.Scene()
        var action = restartAction()
        scene.addChild({ child: new action() })

        director.replaceScene(scene)
    },

    backCallback: function () {
        var director = cocos.Director.sharedDirector

        var scene = new nodes.Scene()
        var action = backAction()
        scene.addChild({ child: new action() })

        director.replaceScene(scene)
    },

    nextCallback: function () {
        var director = cocos.Director.sharedDirector

        var scene = new nodes.Scene()
        var action = nextAction()
        scene.addChild({ child: new action() })

        director.replaceScene(scene)
    },
    
    toTitleCallback: function (){
	console.log( 'derp' );
    },
    toAboutCallback: function (){
        var scene = new Scene()
          , layer = new about_scene()

        // Add our layer to the scene
        scene.addChild(layer)

        // Run the scene
        cocos.Director.sharedDirector.pushScene(scene)
    },
    toDifficultyCallback: function (){
        var scene = new Scene()
          , layer = new difficulty_scene()

        // Add our layer to the scene
        scene.addChild(layer)

        // Run the scene
        cocos.Director.sharedDirector.pushScene(scene)
    }
})

module.exports = title_scene